<%@ page language="java" contentType="text/html; charset=utf-8"	pageEncoding="utf-8"%>
<%@ page import="java.sql.*"%>
<%request.setCharacterEncoding("UTF-8"); %>
<jsp:useBean id="studentBean" class="cn.StudentBean"></jsp:useBean>
<jsp:setProperty property="*" name="studentBean"></jsp:setProperty>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=uft-8">
    
    <title>更新页面</title>
 
  </head>
  <body>
    <br>

   <% 
  try{
	Class.forName("com.mysql.jdbc.Driver");  
    String url = "jdbc:mysql://localhost:3306/jsp";  
    String use = "root";   
    String password = "root"; 
  
    Connection conn= DriverManager.getConnection(url,use,password);  
      
    String sql="insert into tb_student(username,name,number,sex) values(?,?,?,?)";
    PreparedStatement ps =conn.prepareStatement(sql);
    ps.setString(1,studentBean.getUsername());
    ps.setString(2,studentBean.getName());
    ps.setInt(3,studentBean.getNumber());
    ps.setString(4,studentBean.getSex());
    int row=ps.executeUpdate();
    if(row>0){
    	out.print("成功添加"+row+"条数据！");
    	
    }else{
    	 response.sendRedirect("addStudent.jsp");

    }

	  ps.close();
	    conn.close();
  }
   catch(Exception e){
	   e.printStackTrace();
   }
   %>
<a href="student_system.jsp">返回</a>
  </body>
</html>